package com.lq.commonclass;

import java.util.Locale;
/**
 * String类练习
 * @author liuqing
 * @since 2022/2/17
 */
public class StringDemo {
    public static void main(String[] args) {
        String str = "萨瓦迪卡";
        String str1 = "a=bc=d";
        str.length(); //字符串长度
        str.charAt(2); //得到索引为2的字符
        System.out.println(str.compareTo(str1)); // 字符串比较 相同0
        System.out.println(str1.indexOf("d")); //返回第一次出现的索引
        System.out.println(str1.substring(1)); // 截取
        String[] split = str1.split("=");   //拆分的结果保存在字符串数组中
        for (int i = 0; i < split.length; i++) {
            System.out.println("拆分" + split[i]);
        }

        String str2 = "music";
        String str3 = "dog";
        String concat = str2.concat(str3);  //合并字符串
        System.out.println("合并后的"+concat);
        System.out.println(str2.toUpperCase(Locale.ROOT)); // 转大写
        String replace = str3.replace("d", "a"); //替换后原来字符串的内容不变
        System.out.println(replace);
        System.out.println(str3.equals(replace));



    }
}
